import _ImagePicker from './ImagePicker.vue'
import { createVNode, render } from 'vue'

export const ImagePicker = {
  picker () {
    return new Promise<string>(function (resolve, reject) {
      const node = document.createElement('div')

      // node.setAttribute('c-self-configuring-image-picker', '')
      document.body.appendChild(node)
      const instance = createVNode(_ImagePicker, {
        resolve (e: string) {
          unmountImagePicker(node)
          resolve(e.toString())
        },
        reject (e) {
          unmountImagePicker(node)
          reject(e)
        }
      })
      // 修改参数 instance.component.props
      render(instance, node)
    })
  }
}

function unmountImagePicker (node) {
  render(null, node)
  node.remove()
}
